<template>
  <section>
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true">
        <el-form-item>
          <el-input v-model="keyword" placeholder="关键字"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="warning" @click="keywordQuery">查询</el-button>
        </el-form-item>
      </el-form>
    </el-col>

    <!--列表v-loading="listLoading"-->
    <el-table :data="tableDatas" v-loading="listLoading"  highlight-current-row
              style="width: 100%;">
      <!--多选框-->
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column type="index" width="70" label="序号">
      </el-table-column>
      <el-table-column prop="name" label="权限名称" width="120">
      </el-table-column>
      <el-table-column prop="url" label="接口地址" width="120">
      </el-table-column>
      <el-table-column prop="sn" label="权限编码" width="150">
      </el-table-column>
      <el-table-column prop="descs" label="权限描述"  show-overflow-tooltip>
      </el-table-column>
<!--      <el-table-column label="操作">-->
<!--        <template scope="scope">&lt;!&ndash; scope当前行数据 &ndash;&gt;-->
<!--          <el-button size="small" @click="handleEdit(scope.row)">编辑</el-button>-->
<!--        </template>-->
<!--      </el-table-column>-->
    </el-table>
    <!--工具条-->
    <el-col :span="24" class="toolbar">

      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="currentPage"
                     :page-sizes="[5, 10, 15]" :page-size="pageSize" layout="total, sizes, prev, pager, next, jumper"
                     :total="totals" style="float:right;">
      </el-pagination>
    </el-col>
  </section>
</template>

<script >

export default {
  data() {
    return {
      //1.分页查询相关数据
      totals: 0,//总记录条数
      currentPage: 1,//当前页,要传递到后台的
      pageSize: 5, //每页显示多少条
      tableDatas: [], //当前页数据
      listLoading: false,

      //2.高级查询相关数据
      keyword: '',

      //3.删除相关数据

      //4.批量删除相关数据
      sels: [], //存储多选记录

      //5.添加和修改相关数据
      saveFormVisible: false,
      saveForm: {
        id: null,
        userName: '',
        realName: '',
        email: '',
        password: '', //后端需要通过md5加密
        remark: '',
        phone: ''
        //avatar头像 - 前端没有传递 - 需要文件上传
        //logininfo_id - 后端业务生成
      },

      //6.添加和修改校验规则-表单项校验
      saveFormRules: {
        userName: [
          { required: true, message: '请输入用户名称', trigger: 'blur' }
        ],
        phone: [
          { required: true, message: '请输入电话号码', trigger: 'blur' },
          { min: 11, max: 11, message: '请输入正确的手机号', trigger: 'blur' }
        ],
        password: [
          { required: true, message: '请输入登录密码', trigger: 'blur' },
          { min: 6, max: 16, message: '长度在 6 到 16 个字符', trigger: 'blur' }
        ]
      },

    }
  },
  methods: {
    //1.分页查询相关方法
    //1.1.获取列表数据
    getTableData() {
      //构建参数
      var data = {
        "keyword":this.keyword,  // key【后端的接收参数一样】 : value【前端data里面的值】
        "page":this.currentPage,// key【后端的接收参数一样】 : value【前端data里面的值】
        "size":this.pageSize    // key【后端的接收参数一样】 : value【前端data里面的值】
      }
      this.$http.post("/permission/page",data)
          .then(res=>{
            console.log(res)
            if(res.data.success){//成功显示数据
              this.tableDatas = res.data.data.list
              this.totals = res.data.data.total;
            }else {//失败提示信息
              this.$message.error(res.data.msg);
            }
          }).catch(res=>{//是当前请求发送失败才会触发
        console.log(res)
      })
    },
    //1.2.选择第几页时触发
    handleCurrentChange(curentPage) {
      this.currentPage = curentPage;
      this.getTableData();
    },
    //1.3.选择每页显示记录条数时触发
    handleSizeChange(pageSize) {
      this.pageSize = pageSize;
      this.getTableData();
    },

    //2.高级查询相关方法
    keywordQuery() {
      this.getTableData();
    },
  },
  mounted() {
    this.getTableData();
  }
}

</script>

<style scoped lang="scss">

</style>
